<template>
	<view class="jnpf-wrap jnpf-wrap-workflow">
		<u-form :model="dataForm" ref="dataForm" :errorType="['toast']" label-position="left" label-width="180"
			label-align="left">

			<u-form-item label="单别">
				<u-input v-model="dataForm.te001" disabled></u-input>
			</u-form-item>
			<u-form-item label="客户编号" type="textarea">
				<u-input v-model="dataForm.te007" disabled></u-input>
			</u-form-item>
			<u-form-item label="客户名称" type="textarea">
				<!-- <u-input v-model="dataForm.ma002" disabled></u-input> -->
			</u-form-item>
			<u-form-item label="变更日期" type="textarea">
				<u-input v-model="dataForm.te004" disabled></u-input>
			</u-form-item>
			<u-form-item label="新交货日期" type="textarea">
				<u-input v-model="dataForm.tei01" disabled></u-input>
			</u-form-item>
			<u-form-item label="新交货日期" type="textarea">
				<u-input v-model="dataForm.tei01" disabled></u-input>
			</u-form-item>
			<u-form-item label="新安装调试完成日期" type="textarea">
				<u-input v-model="dataForm.tei02" disabled></u-input>
			</u-form-item>
			<u-form-item label="单号" type="textarea">
				<u-input v-model="dataForm.te002" disabled></u-input>
			</u-form-item>
			<u-form-item label="整张结束" type="textarea">

				<u-radio-group v-model="dataForm.te005">
					<u-radio v-for="(item, index) in radioList" :key="index" :name="item.id">{{ item.fullName }}
					</u-radio>
				</u-radio-group>
			</u-form-item>
			<u-form-item label="单据日期" type="textarea">
				<u-input v-model="dataForm.te038" disabled></u-input>
			</u-form-item>
			<u-form-item label="变更原因" type="textarea">
				<u-input v-model="dataForm.te006" disabled></u-input>
			</u-form-item>
			<u-form-item label="审核者" type="textarea">
				<u-input v-model="dataForm.te039" disabled></u-input>
			</u-form-item>
			<u-form-item label="变更版本" type="textarea">
				<u-input v-model="dataForm.te003" disabled></u-input>
			</u-form-item>
			<u-form-item label="变更版本" type="textarea">
				<u-input v-model="dataForm.te044" disabled></u-input>
			</u-form-item>
			<u-form-item label="新项目编号" type="textarea">
				<u-input v-model="dataForm.te065" disabled></u-input>
			</u-form-item>
			<u-form-item label="附件">
				<jnpf-file v-model="dataForm.attachmentUpload" />
			</u-form-item>
			<u-divider color="#fa3534">其他信息</u-divider>
			<u-form-item label="新业务人员" type="textarea">
				<u-input v-model="dataForm.te009" disabled></u-input>
			</u-form-item>
			<u-form-item label="新客户单号" type="textarea">
				<u-input v-model="dataForm.te015" disabled></u-input>
			</u-form-item>
			<u-form-item label="新客户单号" type="textarea">
				<u-input v-model="dataForm.te015" disabled></u-input>
			</u-form-item>
			<u-form-item label="打印次数" type="textarea">
				<u-input v-model="dataForm.te030" disabled></u-input>
			</u-form-item>
			<u-form-item label="来源码" type="textarea">
				<u-input v-model="dataForm.te146" disabled></u-input>
			</u-form-item>
			<u-form-item label="新部门编号" type="textarea">
				<u-input v-model="dataForm.te008" disabled></u-input>
			</u-form-item>
			<u-form-item label="新价格说明" type="textarea">
				<u-input v-model="dataForm.te016" disabled></u-input>
			</u-form-item>
			<u-form-item label="新出货工厂" type="textarea">
				<u-input v-model="dataForm.te010" disabled></u-input>
			</u-form-item>
			<u-form-item label="新付款条件" type="textarea">
				<u-input v-model="dataForm.te017" disabled></u-input>
			</u-form-item>
			<u-form-item label="新交易币种" type="textarea">
				<u-input v-model="dataForm.te011" disabled></u-input>

			</u-form-item>
			<u-form-item label="税种" type="textarea">

				<span v-if="dataForm.te018==1">含税</span>
				<span v-if="dataForm.te018==9">不含税</span>
			</u-form-item>
			<u-form-item label="新汇率" type="textarea">
				<u-input v-model="dataForm.te012" disabled></u-input>
			</u-form-item>

			<u-form-item label="超限放行" type="textarea">
				<u-radio-group v-model="dataForm.te059">
					<u-radio v-for="(item, index) in radioList" :key="index" :name="item.id">{{ item.fullName }}
					</u-radio>
				</u-radio-group>
			</u-form-item>
			<u-form-item label="订金比率" type="textarea">
				<u-input v-model="dataForm.te042" disabled></u-input>
			</u-form-item>
			<u-form-item label="新送货地址(一)" type="textarea">
				<u-input v-model="dataForm.te013" disabled></u-input>
			</u-form-item>
			<u-form-item label="新送货地址(二)" type="textarea">
				<u-input v-model="dataForm.te014" disabled></u-input>
			</u-form-item>
			<u-form-item label="新税号" type="textarea">
				<u-input v-model="dataForm.te061" disabled></u-input>
			</u-form-item>
			<u-form-item label="新电话" type="textarea">
				<u-input v-model="dataForm.te062" disabled></u-input>
			</u-form-item>
			<u-form-item label="新传真" type="textarea">
				<u-input v-model="dataForm.te063" disabled></u-input>
			</u-form-item>
			<u-form-item label="合同类型" type="textarea">
				<u-input v-model="dataForm.te060" disabled></u-input>
			</u-form-item>
			<view class="jnpf-table" style="margin-top: 24rpx;">
				<view class="jnpf-table-item" style="margin-bottom: 24rpx;" v-for="(item,i) in dataForm.coptfList"
					:key="i">
					<u-form-item label="序号">
						{{i+1}}
					</u-form-item>
					<u-form-item label="原序号">
						<u-input v-model="item.tf104" disabled></u-input>
					</u-form-item>
					<u-form-item label="新品号">
						<u-input v-model="item.tf005" disabled></u-input>
					</u-form-item>
					<u-form-item label="新品名">
						<u-input v-model="item.tf006" disabled></u-input>
					</u-form-item>
					<u-form-item label="新规格">
						<u-input v-model="item.tf007" disabled></u-input>
					</u-form-item>
					<u-form-item label="仓库">
						<u-input v-model="item.tf008" disabled></u-input>
					</u-form-item>
					<u-form-item label="新订单数量">
						<u-input v-model="item.tf009" disabled></u-input>
					</u-form-item>
					<u-form-item label="原已交数量">
						<u-input v-model="item.tf123" disabled></u-input>
					</u-form-item>
					<u-form-item label="新赠品量">
						<u-input v-model="item.tf020" disabled></u-input>
					</u-form-item>
					<u-form-item label="原赠品已交量">
						<u-input v-model="item.tf124" disabled></u-input>
					</u-form-item>
					<u-form-item label="新单位">
						<u-input v-model="item.tf010" disabled></u-input>
					</u-form-item>
					<u-form-item label="选配模式">
						<u-input v-model="item.mb443" disabled></u-input>
					</u-form-item>
					<u-form-item label="新配置方案">
						<u-input v-model="item.tf046" disabled></u-input>
					</u-form-item>
					<u-form-item label="描述">
						<u-input v-model="item.tq003" disabled></u-input>
					</u-form-item>
					<u-form-item label="新单价">
						<u-input v-model="item.tf013" disabled></u-input>
					</u-form-item>
					<u-form-item label="税率">
						<u-input v-model="item.tf029" disabled></u-input>
					</u-form-item>
					<u-form-item label="新折扣率">
						<u-input v-model="item.tf021" disabled></u-input>
					</u-form-item>
					<u-form-item label="新金额">
						<u-input v-model="item.tf014" disabled></u-input>
					</u-form-item>
					<u-form-item label="税前金额">
						<u-input v-model="item.tf030" disabled></u-input>
					</u-form-item>
					<u-form-item label="税额">
						<u-input v-model="item.tf031" disabled></u-input>
					</u-form-item>
					<u-form-item label="新预交货日">
						<u-input v-model="item.tf015" disabled></u-input>
					</u-form-item>
					<u-form-item label="新包装方式">
						<u-input v-model="item.tf023" disabled></u-input>
					</u-form-item>
					<u-form-item label="包装名称">
						<u-input v-model="item.packagingName" disabled></u-input>
					</u-form-item>
					<u-form-item label="新毛重(Kg)">
						<u-input v-model="item.tf024" disabled></u-input>
					</u-form-item>
					<u-form-item label="新材积(CUFT)">
						<u-input v-model="item.tf025" disabled></u-input>
					</u-form-item>
					<u-form-item label="原客户品号">
						<u-input v-model="item.tf116" disabled></u-input>
					</u-form-item>
					<u-form-item label="名称">
						<u-input v-model="item.khpm" disabled></u-input>
					</u-form-item>
					<u-form-item label="规格">
						<u-input v-model="item.khgg" disabled></u-input>
					</u-form-item>
					<u-form-item label="预测编号">
						<u-input v-model="item.tf036" disabled></u-input>
					</u-form-item>
					<u-form-item label="预测序号">
						<u-input v-model="item.tf035" disabled></u-input>
					</u-form-item>
					<u-form-item label="新项目编号">
						<u-input v-model="item.tf022" disabled></u-input>
					</u-form-item>
					<u-form-item label="新结束">
						<u-input v-model="item.tf017" disabled></u-input>
					</u-form-item>
					<u-form-item label="变更原因">
						<u-input v-model="item.tf018" disabled></u-input>
					</u-form-item>
					<u-form-item label="新原始客户">
						<u-input v-model="item.tf032" disabled></u-input>
					</u-form-item>
					<u-form-item label="备注">
						<u-input v-model="item.tf033" disabled></u-input>
					</u-form-item>
					<u-form-item label="前置单据单号">
						<u-input v-model="item.tf040" disabled></u-input>
					</u-form-item>
					<u-form-item label="新本币税前金额">
						<u-input v-model="item.tfi01" disabled></u-input>
					</u-form-item>
					<u-form-item label="新本币税额">
						<u-input v-model="item.tfi02" disabled></u-input>
					</u-form-item>
					<u-form-item label="新本币金额">
						<u-input v-model="item.tfi03" disabled></u-input>
					</u-form-item>
					<u-form-item label="新分期期别">
						<u-input v-model="item.tf042" disabled></u-input>
					</u-form-item>
					<u-form-item label="新零组件发货">

						<u-radio-group v-model="dataForm.tf051">
							<u-radio v-for="(item, index) in radioList" :key="index" :name="item.id">{{ item.fullName }}
							</u-radio>
						</u-radio-group>
					</u-form-item>
					<u-form-item label="新零组件接收仓库">
						<u-input v-model="item.tf052" disabled></u-input>
					</u-form-item>
					<u-form-item label="新零组件接收库位">
						<u-input v-model="item.tf053" disabled></u-input>
					</u-form-item>
				</view>
			</view>



		</u-form>
	</view>
</template>
<script>
	import {
		getCopte
	} from "@/api/workFlow/flowEngine";
	import {
		getUserAll,
		Interface,
		getDictionaryDataSelector,
		getDataInterfaceDataInfo
	} from "@/api/common";
	import comMixin from "../mixin";
	import {
		getGoodsList,
		getCustomerList,
		Info,
		Create,
		Update,
	} from "@/api/apply/order";
	export default {
		name: "crmOrder",
		mixins: [comMixin],
		data() {
			return {
				radioList: [{
						fullName: 'Y',
						id: 'Y'
					},
					{
						fullName: 'N',
						id: 'N'
					},
				],
				childrenShow: false,
				childrenName: "",
				dataForm: {},
				tableField133: [],
				id: "",
				wx022Name: [],
				wx023Name: [],
				wx018Name: [],
				wx020Name: [],
				nameList: [],
				xx032List: [],
				tn003List: [],
				childrenList: [],
			};
		},

		methods: {
			init(data, id, flowFormContentJson) {
				this.setting = data;
				this.id = id;
				this.getInfo(data);
			},
			childNodes(item) {
				if (item.children.length == 0) return;
				this.childrenList = item.children;
				this.childrenName = item.tb004 + "-子节点";
				this.childrenShow = true;
			},
			getDynamicStyle(item) {
				return {
					"background-color": item.children && item.children.length > 0 ? "aqua" : "",
				};
			},
			// 转换时间到时
			formattedTime(time = "0000000000") {
				if (!time) return "";
				return (
					time.slice(0, 4) +
					"-" +
					time.slice(4, 6) +
					"-" +
					time.slice(6, 8) +
					" " +
					time.slice(8, 10)
				);
			},
			// 转换时间到日
			formattedData(data = "00000000") {
				if (!data) return "";
				return data.slice(0, 4) + "-" + data.slice(4, 6) + "-" + data.slice(6, 8);
			},
			formattedName(id) {
				// 找到匹配的ID并返回名字
				const person = this.nameList.find((p) => p.id === id);
				return person ? person.realName : "";
			},
			formattedtn003(tn003) {
				// 找到匹配的ID并返回名字
				const obj = this.tn003List.find((p) => p.id === tn003);
				return obj ? obj.fullName : "";
			},
			formattedsortCode(xx032) {
				const obj = this.xx032List.find((p) => p.sortCode == xx032);
				return obj ? obj.fullName : "";
			},
			getInfo(data) {
				console.log('data', data);
				getCopte(data.id).then((res) => {
					console.log('res', res);
					if (res.code == 200) {
						this.dataForm = res.data;
						this.gette060Options();
						this.getDataInterfaceDataInfote007(this.dataForm.te007);
						this.getDataInterfaceDataInfote010(this.dataForm.te010);
						this.getDataInterfaceDataInfocg();
					}
				});
			},
			// 获取合同类型
			gette060Options() {
				getDictionaryDataSelector("411696718036353989").then((res) => {
					const matchedItem = res.data.list.filter(item => item.enCode == this.dataForm.te060)[0];
					this.dataForm.te060 = matchedItem ? matchedItem.fullName : null;
				});
			},
			getDataInterfaceDataInfote007(id) {

				let data = {
					id,
					interfaceId: '362118781926906437',
					propsValue: 'MA001',
					relationField: 'JoinStr',
				}
				getDataInterfaceDataInfo('362118781926906437', data).then(res => {
					if (res.code == 200) {
						this.dataForm.te007 = res.data.JoinStr
					}
				})
			},
			getDataInterfaceDataInfote010(id) {
				let data = {
					id,
					interfaceId: '362111000289221189',
					propsValue: 'MB001',
					relationField: 'MB002',
				}
				getDataInterfaceDataInfo('362111000289221189', data).then(res => {
					if (res.code == 200) {
						console.log('res', res);
						this.dataForm.te010 = res.data.JoinStr
					}
				})
			},
			getDataInterfaceDataInfocg() {
				let list = this.dataForm.coptfList
				for (let i = 0; i < list.length; i++) {
					let data = {
						id: list[i].tf008,
						interfaceId: '362114335423601221',
						propsValue: 'MC001',
						relationField: 'MC001',
					}
					getDataInterfaceDataInfo('362114335423601221', data).then(res => {
						this.dataForm.coptfList[i].tf008 = res.data.MC002
					})
				}

			},
			// 获取优先级
			getxz009Options() {
				getDictionaryDataSelector("505518936847035461").then((res) => {});
			},
			getUser() {
				getUserAll().then((res) => {
					this.nameList = res.data;
					this.wx022Name = res.data
						.filter((item) => this.dataForm.wx022.includes(item.id))
						.map((item) => item.realName);

					this.wx023Name = res.data
						.filter((item) => this.dataForm.wx023.includes(item.id))
						.map((item) => item.realName);

					this.wx018Name = res.data
						.filter((item) => this.dataForm.wx018.includes(item.id))
						.map((item) => item.realName);
					this.wx020Name = res.data
						.filter((item) => this.dataForm.wx020.includes(item.id))
						.map((item) => item.realName);
				});
			},
			getInterface() {
				Interface().then((res) => {
					this.tn003List = res.data;
				});
			},
			selfGetInfo() {
				Info(this.setting.id).then((res) => {
					this.dataForm = res.data;
					if (this.dataForm.fileJson) {
						this.fileList = JSON.parse(this.dataForm.fileJson);
					}
				});
			},
			selfSubmit() {
				this.dataForm.status = this.eventType === "submit" ? 0 : 1;
				if (this.eventType === "save") return this.selfHandleRequest();
				uni.showModal({
					title: "提示",
					content: "您确定要提交当前流程吗？",
					success: (res) => {
						if (res.confirm) {
							this.selfHandleRequest();
						}
					},
				});
			},
			selfHandleRequest() {
				if (!this.dataForm.id) delete this.dataForm.id;
				const formMethod = this.dataForm.id ? Update : Create;
				formMethod(this.dataForm).then((res) => {
					uni.showToast({
						title: res.msg,
						complete: () => {
							setTimeout(() => {
								uni.$emit("refresh");
								uni.navigateBack();
							}, 1500);
						},
					});
				});
			},
			initData() {
				getGoodsList().then((res) => {
					this.goodsOptions = res.data.list;
				});
				getCustomerList().then((res) => {
					this.customerOptions = res.data.list;
				});
			},
			selfInit() {
				this.addGoods();
				this.addPlan();
			},
			onChange(e) {
				const user = e[0];
				this.dataForm.salesmanName = user.fullName;
			},
			addGoods() {
				const item = {
					goodsId: "",
					goodsCode: "",
					goodsName: "",
					specifications: "",
					unit: "",
					qty: "",
					price: "",
					amount: "",
					discount: null,
					cess: null,
					actualPrice: "",
					actualAmount: "",
					description: "",
				};
				this.dataForm.goodsList.push(item);
			},
			delGoods(index) {
				this.dataForm.goodsList.splice(index, 1);
			},
			addPlan() {
				const item = {
					receivableDate: "",
					receivableRate: "",
					receivableMoney: "",
					receivableMode: "",
					abstract: "",
				};
				this.dataForm.collectionPlanList.push(item);
			},
			delPlan(index) {
				this.dataForm.collectionPlanList.splice(index, 1);
			},
			onGoodsChange(e, i) {
				const goods = e[0];
				this.dataForm.goodsList[i] = {
					goodsId: goods.id,
					goodsCode: goods.code,
					goodsName: goods.text,
					specifications: goods.specifications,
					unit: goods.unit,
					qty: 1,
					price: goods.price,
					amount: goods.price,
					discount: 100,
					cess: 0,
					actualPrice: goods.price,
					actualAmount: goods.price,
					description: "",
				};
				this.$forceUpdate();
			},
			onCustomerChange(e) {
				const customer = e[0];
				this.dataForm.customerName = customer.text;
			},
			count(row) {
				//金额 = 数量*单价
				row.amount = this.jnpf.toDecimal(
					parseFloat(row.price) * parseFloat(row.qty)
				);
				//折扣价 = (单价*折扣)
				var discountPrice = row.price * (row.discount / 100);
				//实际单价 = 折扣价 * (1 + (税率 / 100))
				row.actualPrice = this.jnpf.toDecimal(
					discountPrice * (1 + row.cess / 100)
				);
				//实际金额
				row.actualAmount = this.jnpf.toDecimal(
					parseFloat(row.actualPrice) * parseFloat(row.qty)
				);
				this.$forceUpdate();
			},
		},
	};
</script>